#ifndef BUZZLOCK_H
#define BUZZLOCK_H
#include <unistd.h>
#include <pthread.h>
#include "hash_table.h"
#include <semaphore.h>
#define BZZ_BLACK 1
#define BZZ_GOLD 2

//#define MY_DEBUG
#ifdef MY_DEBUG
#define DPRINT(x) printf x
#else
#define DPRINT(x)
#endif

typedef struct bzz {
    sem_t mutex;
    int in_use;
    pthread_mutex_t queue_mutex;
    pthread_cond_t black_cond;
    pthread_cond_t old_gold_cond;
    pthread_cond_t new_gold_cond;
    int black, old_gold, new_gold;
    int bsig, ogsig, ngsig;
    hash_table *tbl;
    int timeout;
    int num_threads;
} bzz;

typedef bzz * bzz_t;
void init_bzz(bzz_t *, int, useconds_t);
void bzz_color(int, bzz_t);
void bzz_lock(bzz_t);
void bzz_release(bzz_t);
void bzz_kill(bzz_t);

#endif
